/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class TransactionItem
    {
    
        private String transactionItemIdField;

        private String quantityField;

        private  Price unitPriceField;
        private  Price totalPriceField;
        private String ASINField;

        private  ChildTransactionItems childTransactionItemsField;

        /// <summary>
        /// Gets and sets the TransactionItemId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TransactionItemId")]
        public String TransactionItemId
        {
            get { return this.transactionItemIdField ; }
            set { this.transactionItemIdField= value; }
        }



        /// <summary>
        /// Sets the TransactionItemId property
        /// </summary>
        /// <param name="transactionItemId">TransactionItemId property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithTransactionItemId(String transactionItemId)
        {
            this.transactionItemIdField = transactionItemId;
            return this;
        }



        /// <summary>
        /// Checks if TransactionItemId property is set
        /// </summary>
        /// <returns>true if TransactionItemId property is set</returns>
        public Boolean IsSetTransactionItemId()
        {
            return  this.transactionItemIdField != null;

        }


        /// <summary>
        /// Gets and sets the Quantity property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Quantity")]
        public String Quantity
        {
            get { return this.quantityField ; }
            set { this.quantityField= value; }
        }



        /// <summary>
        /// Sets the Quantity property
        /// </summary>
        /// <param name="quantity">Quantity property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithQuantity(String quantity)
        {
            this.quantityField = quantity;
            return this;
        }



        /// <summary>
        /// Checks if Quantity property is set
        /// </summary>
        /// <returns>true if Quantity property is set</returns>
        public Boolean IsSetQuantity()
        {
            return  this.quantityField != null;

        }


        /// <summary>
        /// Gets and sets the UnitPrice property.
        /// </summary>
        [XmlElementAttribute(ElementName = "UnitPrice")]
        public Price UnitPrice
        {
            get { return this.unitPriceField ; }
            set { this.unitPriceField = value; }
        }



        /// <summary>
        /// Sets the UnitPrice property
        /// </summary>
        /// <param name="unitPrice">UnitPrice property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithUnitPrice(Price unitPrice)
        {
            this.unitPriceField = unitPrice;
            return this;
        }



        /// <summary>
        /// Checks if UnitPrice property is set
        /// </summary>
        /// <returns>true if UnitPrice property is set</returns>
        public Boolean IsSetUnitPrice()
        {
            return this.unitPriceField != null;
        }




        /// <summary>
        /// Gets and sets the TotalPrice property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TotalPrice")]
        public Price TotalPrice
        {
            get { return this.totalPriceField ; }
            set { this.totalPriceField = value; }
        }



        /// <summary>
        /// Sets the TotalPrice property
        /// </summary>
        /// <param name="totalPrice">TotalPrice property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithTotalPrice(Price totalPrice)
        {
            this.totalPriceField = totalPrice;
            return this;
        }



        /// <summary>
        /// Checks if TotalPrice property is set
        /// </summary>
        /// <returns>true if TotalPrice property is set</returns>
        public Boolean IsSetTotalPrice()
        {
            return this.totalPriceField != null;
        }




        /// <summary>
        /// Gets and sets the ASIN property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ASIN")]
        public String ASIN
        {
            get { return this.ASINField ; }
            set { this.ASINField= value; }
        }



        /// <summary>
        /// Sets the ASIN property
        /// </summary>
        /// <param name="ASIN">ASIN property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithASIN(String ASIN)
        {
            this.ASINField = ASIN;
            return this;
        }



        /// <summary>
        /// Checks if ASIN property is set
        /// </summary>
        /// <returns>true if ASIN property is set</returns>
        public Boolean IsSetASIN()
        {
            return  this.ASINField != null;

        }


        /// <summary>
        /// Gets and sets the ChildTransactionItems property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ChildTransactionItems")]
        public ChildTransactionItems ChildTransactionItems
        {
            get { return this.childTransactionItemsField ; }
            set { this.childTransactionItemsField = value; }
        }



        /// <summary>
        /// Sets the ChildTransactionItems property
        /// </summary>
        /// <param name="childTransactionItems">ChildTransactionItems property</param>
        /// <returns>this instance</returns>
        public TransactionItem WithChildTransactionItems(ChildTransactionItems childTransactionItems)
        {
            this.childTransactionItemsField = childTransactionItems;
            return this;
        }



        /// <summary>
        /// Checks if ChildTransactionItems property is set
        /// </summary>
        /// <returns>true if ChildTransactionItems property is set</returns>
        public Boolean IsSetChildTransactionItems()
        {
            return this.childTransactionItemsField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetTransactionItemId()) {
                xml.Append("<TransactionItemId>");
                xml.Append(EscapeXML(this.TransactionItemId));
                xml.Append("</TransactionItemId>");
            }
            if (IsSetQuantity()) {
                xml.Append("<Quantity>");
                xml.Append(EscapeXML(this.Quantity));
                xml.Append("</Quantity>");
            }
            if (IsSetUnitPrice()) {
                Price  unitPrice = this.UnitPrice;
                xml.Append("<UnitPrice>");
                xml.Append(unitPrice.ToXMLFragment());
                xml.Append("</UnitPrice>");
            } 
            if (IsSetTotalPrice()) {
                Price  totalPrice = this.TotalPrice;
                xml.Append("<TotalPrice>");
                xml.Append(totalPrice.ToXMLFragment());
                xml.Append("</TotalPrice>");
            } 
            if (IsSetASIN()) {
                xml.Append("<ASIN>");
                xml.Append(EscapeXML(this.ASIN));
                xml.Append("</ASIN>");
            }
            if (IsSetChildTransactionItems()) {
                ChildTransactionItems  childTransactionItems = this.ChildTransactionItems;
                xml.Append("<ChildTransactionItems>");
                xml.Append(childTransactionItems.ToXMLFragment());
                xml.Append("</ChildTransactionItems>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}